import { httpFetch } from '../../utils/req'
// import AES from "../cryptoPwd.js"
// POST https://api.jinkex.com/edu/v1/student/login
// data {"school_host":"haut.hnscen.cn","token":"","device":"app","num":"201983020095","password":"123456"}

// Cookie
// 	065df9c8090f46bbbceecdc880f43458=WyIyMDczMTUzMjc3Il0; 1a28e23538344d17836a8557bc6cdd84=WyIzNDA2NzQyNzEzIl0

const headers = {
  Cookie: '',
  Authorization: 'haut.hnscen.cn',
  Host: 'api.jinkex.com',
  Referer: 'https://haut.hnscen.cn/',
  Origin: 'https://haut.hnscen.cn',
  'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.0',
  'Sec-Fetch-Dest': 'empty',
  'Sec-Fetch-Mode': 'cors',
  'Sec-Fetch-Site': 'cross-site',
  'Content-Type': 'application/json;charset=utf-8'
}

const url = 'https://api.jinkex.com/edu/v1/student/login'

export default (query, request) => {
  return new Promise((resolve, reject) => {
    const name = query.name
    const pwd = query.pwd

    if (name && pwd) {
      const data = {
        school_host: 'haut.hnscen.cn',
        token: '',
        device: 'app',
        num: name,
        password: pwd
      }
      httpFetch(
        url,
        {
          method: 'post',
          body: data,
          headers: headers
        }
      ).promise.then(res => {
        resolve(res.body)
      }).catch(e => {
        reject(e)
      })
    } else {
      const rt = {
        name: '错误',
        message: '请输入账号和密码'
      }
      reject(rt)
    }
  })
}
